#
# Common reporting subroutines for the Linux Counter
# It should be a module; I will learn how to do it when I
# understand Export....
#


sub readfile {
    my($file, $fields, $sums) = @_;
    my $field;
    open(PERS, $file) || die "Unable to open $file\n";
    while (<PERS>) {
	chop;
	if (/^\/\/.*:(\S+)$/) {
	    $field = $1;
	} elsif (/^"(.*)":(\d+)$/) {
	    $$fields{$field}{$1} = $2;
	} elsif (/^(\S+):(\d+)$/) {
	    $$sums{$field}{$1} = $2;
	} else {
	    print STDERR "Unparsed line: $_\n";
	}
    }
}

sub printwithcommas {
    my $number = shift;
    my $string;

    while ($number > 1000) {
	$string = sprintf(",%03d", $number % 1000) . $string;
	$number /= 1000;
    }
    $string = sprintf("%d", $number) . $string;
    $string;
}

1;
